/***************************************************************************
 *   Copyright (C) 2007 by Warren Kenny   *
 *   warren.kenny@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "otaSessionKey.h"

otaSessionKey::otaSessionKey()
{
	
}

otaSessionKey::otaSessionKey( unsigned long sourceIP, unsigned short sourcePort, unsigned long destinationIP, unsigned short destinationPort )
{
	m_sourceIP = sourceIP;
	m_destinationIP = destinationIP;
	
	m_sourcePort = sourcePort;
	m_destinationPort = destinationPort;
}

int otaSessionKey::operator<(const otaSessionKey& session) const
{
	if( m_destinationIP == session.m_destinationIP )
	{
		if( m_sourceIP == session.m_sourceIP )
		{
			if( m_destinationPort == session.m_destinationPort )
			{
				return ( m_sourcePort < session.m_sourcePort );
			}
			else
			{
				return ( m_destinationPort < session.m_destinationPort );
			}
		}
		else
		{
			return( m_sourceIP < session.m_sourceIP );
		}
	}
	else if( m_destinationIP == session.m_sourceIP )
	{
		if( m_sourceIP == session.m_destinationIP )
		{
			if( m_destinationPort == session.m_sourcePort )
			{
				return( m_sourcePort < session.m_destinationPort );
			}
			else
			{
				return( m_destinationPort < session.m_sourcePort );
			}
		}
		else
		{
			return( m_sourceIP < session.m_destinationIP );
		}
	}
	else if( m_sourceIP == session.m_destinationIP )
	{
		if( m_destinationIP == session.m_sourceIP )
		{
			if( m_sourcePort == session.m_destinationPort )
			{
				return( m_destinationPort < session.m_sourcePort );
			}
			else
			{
				return( m_sourcePort < session.m_destinationPort );
			}
		}
		else
		{
			return( m_sourceIP < session.m_destinationIP );
		}
	}
	else if( m_sourceIP == session.m_sourceIP )
	{
		if( m_destinationIP == session.m_destinationIP )
		{
			if( m_sourcePort == session.m_sourcePort )
			{
				return ( m_destinationPort < session.m_destinationPort );
			}
			else
			{
				return ( m_sourcePort < session.m_sourcePort );
			}
		}
		else
		{
			return( m_sourceIP < session.m_sourceIP );
		}
	}
	else
	{
		return( m_sourceIP < session.m_sourceIP );
	}
}

bool otaSessionKey::operator==(const otaSessionKey& session) const
{
	if(	( m_sourceIP == session.m_sourceIP && m_sourcePort == session.m_sourcePort && m_destinationIP == session.m_destinationIP && m_destinationPort == session.m_destinationPort ) ||
		( m_sourceIP == session.m_destinationIP && m_sourcePort == session.m_destinationPort && m_destinationIP == session.m_sourceIP && m_destinationPort == session.m_sourcePort ) )
	{
		return true;
	}      
	else
	{
		return false;
	}
}

otaSessionKey& otaSessionKey::operator=(const otaSessionKey &key)
{
	m_sourceIP = key.m_sourceIP;
	m_destinationIP = key.m_destinationIP;
	m_sourcePort = key.m_sourcePort;
	m_destinationPort = key.m_destinationPort;
	return *this;
}

unsigned short otaSessionKey::getSourcePort()
{
	return m_sourcePort;
}

unsigned short otaSessionKey::getDestinationPort()
{
	return m_destinationPort;
}
	
unsigned long otaSessionKey::getSourceIP()
{
	return m_sourceIP;
}

unsigned long otaSessionKey::getSourceIP() const
{
	return m_sourceIP;
}

unsigned long otaSessionKey::getDestinationIP()
{
	return m_destinationIP;
}

otaSessionKey::~otaSessionKey()
{
}


